using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.SceneManagement;
using UnityEditor.Build.Reporting;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using QTool.Inspector;
using System;

namespace QTool.NetFrame {
 
    public static class QNetEditor
    {
     
		
        [InitializeOnLoadMethod]
        public static void InitDraw()
        {
            QEditorTool.DrawPropertyToFloat[nameof(Fix64)] = DrawFix64;
			QEditorTool.DrawOverride[typeof(Fix64)] = (value,name) =>
			{
				return (Fix64)(float)QEditorTool.Draw((float)(Fix64)value, name, typeof(float));
			};

		}

        static void DrawFix64(SerializedProperty property, Func<float, float> floatDraw)
        {
            var longValue = property.FindPropertyRelative(nameof(Fix64.RawValue));
            var v = (float)Fix64.Get(longValue.longValue);
            v = floatDraw(v);
            longValue.longValue = ((Fix64)v).RawValue;
		}
		//[MenuItem("QTool/QNet/测试客户端")]
		//public static  void TestClient()
		//{
		//	System.Diagnostics.Process.Start(PlayerPrefs.GetString("QToolBuildPath", QToolEditor.), "client");
		//}
		//[MenuItem("QTool/QNet/测试主机")]
		//public static  void TestHost()
		//{
		//	System.Diagnostics.Process.Start(PlayerPrefs.GetString("QToolBuildPath", QToolEditor.GetBuildPath()), "server");
		//}

		//[MenuItem("QTool/QNet/测试打包(自动运行 主机+客户端)")]
  //      public static async void TestBuildHostAndClient()
  //      {
		
		//	if (!BuildPipeline.isBuildingPlayer)
		//	{
				
		//		var path = QToolEditor.Build(new string[] { SceneManager.GetActiveScene().path }, BuildOptions.Development);
		//		PlayerPrefs.SetString("QToolBuildPath", path);
		//		if (!string.IsNullOrWhiteSpace(path))
		//		{
		//			System.Diagnostics.Process.Start(path, "server");
		//			await Task.Delay(10000);
		//			System.Diagnostics.Process.Start(path, "client");
		//		}
		//	}
  //      }
    }
}
